Permitir correta utilização da evolution quando mensagens não são persistidas no DB#1798
Conversation
…lvar mensagens no banco
Reviewer's GuideRefactor persistence logic to conditionally perform database operations based on configurable SAVE_DATA flags, ensuring correct behavior when messages are not stored. Flow diagram for conditional message persistence logicflowchart TD
A[Receive message update] --> B{SAVE_DATA.HISTORIC or SAVE_DATA.NEW_MESSAGE?}
B -- Yes --> C[Find message in DB]
C -- Found --> D[Set messageId]
C -- Not found --> E[Skip setting messageId]
B -- No --> F[Skip DB lookup]
Flow diagram for conditional message update persistenceflowchart TD
A[Message update event] --> B{SAVE_DATA.MESSAGE_UPDATE?}
B -- Yes --> C[Create messageUpdate in DB]
B -- No --> D[Skip DB operation]
Flow diagram for conditional message edit validationflowchart TD
A[Edit message request] --> B{SAVE_DATA.NEW_MESSAGE?}
B -- Yes --> C[Validate oldMessage exists and is valid]
B -- No --> D[Skip validation]
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @onerrogus - I've reviewed your changes - here's some feedback:
- Cache the DATABASE.SAVE_DATA config at the start of the method or as a class property to avoid repeating configService.get calls and improve readability.
- Extract the conditional logic for historic, new message, and message update handling into dedicated helper methods to reduce nesting and duplication.
- Centralize the SAVE_DATA flag checks into a single guard or utility function to ensure consistent behavior across all message operations.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Cache the DATABASE.SAVE_DATA config at the start of the method or as a class property to avoid repeating configService.get calls and improve readability.
- Extract the conditional logic for historic, new message, and message update handling into dedicated helper methods to reduce nesting and duplication.
- Centralize the SAVE_DATA flag checks into a single guard or utility function to ensure consistent behavior across all message operations.
## Individual Comments
### Comment 1
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3789` </location>
<code_context>
private async formatUpdateMessage(data: UpdateMessageDto) {
try {
+ if (!this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
+ return data;
+ }
</code_context>
<issue_to_address>
Early return skips formatting if NEW_MESSAGE is false.
Ensure that all consumers of this method are prepared to handle unformatted data when NEW_MESSAGE is false, as this may affect downstream processing.
</issue_to_address>
### Comment 2
<location> `src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts:3852` </location>
<code_context>
const messageId = messageSent.message?.protocolMessage?.key?.id;
- if (messageId) {
+ if (messageId && this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) {
let message = await this.prismaRepository.message.findFirst({
where: { key: { path: ['id'], equals: messageId } },
</code_context>
<issue_to_address>
Message update logic is now gated by NEW_MESSAGE flag.
Consider whether message updates should ever occur when NEW_MESSAGE is false, as this change will prevent all such updates.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
|
||
| private async formatUpdateMessage(data: UpdateMessageDto) { | ||
| try { | ||
| if (!this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) { |
There was a problem hiding this comment.
question (bug_risk): Early return skips formatting if NEW_MESSAGE is false.
Ensure that all consumers of this method are prepared to handle unformatted data when NEW_MESSAGE is false, as this may affect downstream processing.
|
|
||
| const messageId = messageSent.message?.protocolMessage?.key?.id; | ||
| if (messageId) { | ||
| if (messageId && this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE) { |
There was a problem hiding this comment.
question (bug_risk): Message update logic is now gated by NEW_MESSAGE flag.
Consider whether message updates should ever occur when NEW_MESSAGE is false, as this change will prevent all such updates.
|
@DavidsonGomes as alterações são referentes ao uso da Evolution sem salvar as mensagens em banco de dados.
Lembrando que essas alterações são referentes a quando as opções na env de SAVE_NEW_MESSAGE está definida como false, no nosso caso, usamos a EvolutionAPI apenas como intermediário para troca de mensagens, com envio e recebimento e re-envio dos eventos via webhook/socket, não utilizamos as tabelas da Evolution para salvar as mensagens. |
Summary by Sourcery
Add configuration flags to control message persistence and history retrieval, enabling selective saving and logging of incoming messages and updates based on SAVE_DATA settings
Enhancements: